home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
COMMANDS
/
RESTOOLS.C
< prev
next >
Wrap
Text File
|
1992-12-02
|
10KB
|
413 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 012290 : Initial
*
*
* dumpr - resource decompiler : RMAKER FORMAT
* dumpr [options] [files]
*
*
* IN PROGRESS
*
* Resource command module
*
* maker - resource compiler : RMAKER FORMAT
* maker [options] [files]
*
*
*/
#include <ResourceMgr.h>
#include "SystemPub.h"
#include "Proc.h"
#include "ShellPub.h"
#include "Path.h"
/*******************************************************************
*
* Function DUMPR
*
* PathName Callback function
*
* usage DUMPR [options] [names]
*
*
*******************************************************************/
char dumpResName[ 64 ];
#define dumprResType (**MyShell).Proc[ProcID].long0
#define dumprSize (**MyShell).Proc[ProcID].long1
#define dumprIDStart (**MyShell).Proc[ProcID].int0
#define dumprIDEnd (**MyShell).Proc[ProcID].int1
#define checkT (**MyShell).Proc[ProcID].int2
#define dumprTypes (**MyShell).Proc[ProcID].bflags.f0
#define dumprIDs (**MyShell).Proc[ProcID].bflags.f1
#define dumprData (**MyShell).Proc[ProcID].bflags.f2
/*******************************************************************/
void dumprDumpRes( WHandle ShellWh, int16 ProcID, OsType theType,
Handle handle )
{
LoadResource( handle );
switch( theType )
{
case 'ALRT' : DumpALRT( ShellWh, ProcID, handle ); break;
case 'BNDL' : DumpBNDL( ShellWh, ProcID, handle ); break;
case 'CNTL' : DumpCNTL( ShellWh, ProcID, handle ); break;
case 'DITL' : DumpDITL( ShellWh, ProcID, handle ); break;
case 'DLOG' : DumpDLOG( ShellWh, ProcID, handle ); break;
case 'FREF' : DumpFREF( ShellWh, ProcID, handle ); break;
case 'MENU' : DumpMENU( ShellWh, ProcID, handle ); break;
case 'STR ' : DumpSTR( ShellWh, ProcID, handle ); break;
case 'STR#' : DumpSTRP( ShellWh, ProcID, handle ); break;
case 'WIND' : DumpWIND( ShellWh, ProcID, handle ); break;
/*
* For expansion
*
case 'XXXX' : DumpXXXX( ShellWh, ProcID, handle ); break;
*/
default: DumpGNRL( ShellWh, ProcID, handle, theType ); break;
}
ReleaseResource( handle );
}
/*******************************************************************/
void dumprDumpType( WHandle ShellWh, int16 ProcID, OsType theType,
int16 numRes )
{
OsType aType;
Boolean dropOut = FALSE;
int16 resID;
Handle h;
char str[ 64 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
while( --numRes && !dropOut && !UserAbort() )
{
h = Get1IndResource( theType, numRes );
if( h )
{
GetResInfo( h, &resID, &aType, str );
if( checkT == 2 )
{
if( resID < dumprIDStart )
continue;
else if( resID > dumprIDEnd )
continue;
}
else if( checkT == 1 )
if( resID != dumprIDStart )
continue;
dumprDumpRes( ShellWh, ProcID, theType, h );
}
if( UserAbort() )
dropOut = TRUE;
}
}
/*******************************************************************/
void dumprDumpName( WHandle ShellWh, int16 ProcID,
OsType theType, char *theName )
{
OsType aType;
Handle h;
char str[ 64 ];
int16 resID;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
strcpy( str, theName );
CtoPstr( str );
h = Get1NamedResource( theType, str );
if( h )
{
GetResInfo( h, &resID, &aType, str );
if( checkT == 2 )
{
if( resID < dumprIDStart )
return;
else if( resID > dumprIDEnd )
return;
}
else if( checkT == 1 )
if( resID != dumprIDStart )
return;
dumprDumpRes( ShellWh, ProcID, theType, h );
}
}
/*******************************************************************/
void DUMPRCallBack( WHandle ShellWh, int16 ProcID, char *path,
char *last, pathType what, int16 vRefNum, int32 dirID )
{
char str[ 64 ];
OSErr err;
int16 refNum, currFile, numTypes, numRes, resID, resFileWasOpen = FALSE;
OsType theType, aType;
Handle h;
Boolean dropOut = FALSE;
FInfo finder;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
if( what == pathIsFile )
{
strcpy( str, last );
CtoPstr( str );
err = HSetVol( NULL, vRefNum, dirID );
if( err )
return;
err = HGetFInfo( vRefNum, dirID, str, &finder );
currFile = CurResFile();
if( ResFileOpen( last, vRefNum, dirID, &refNum ) )
resFileWasOpen = TRUE;
else
refNum = OpenResFile( str );
if( refNum != (-1) )
{
procPrintf( ShellWh, ProcID, "%s\n", last );
TypeToStr( finder.fdType, str );
procPrintf( ShellWh, ProcID, "%s", str );
TypeToStr( finder.fdCreator, str );
procPrintf( ShellWh, ProcID, "%s\n\n", str );
UseResFile( refNum );
SetResLoad( FALSE );
numTypes = Count1Types() + 1;
while( --numTypes && !dropOut && !UserAbort() )
{
Get1IndType( &theType, numTypes ); /* What type is this ? */
numRes = Count1Resources( theType ) + 1;
if( dumprResType && (dumprResType != theType ) )
continue;
if( *dumpResName )
dumprDumpName( ShellWh, ProcID, theType, dumpResName );
else
dumprDumpType( ShellWh, ProcID, theType, numRes );
}
if( !resFileWasOpen )
CloseResFile( refNum );
SetResLoad( TRUE );
UseResFile( currFile );
}
else if( (err = ResError() || refNum == (-1)) && (err != eofErr) )
procPrintf( ShellWh, ProcID, "dumpr : error openning file %s (%d)\n",
last, err );
}
}
/*******************************************************************/
void DUMPRFile( WHandle ShellWh, int16 ProcID, char *argument )
{
ShellWindRec **MyShell;
MyShell = (ShellWindRec **) (**ShellWh).thing;
ExpandPath( ShellWh, ProcID, argument, (ProcPtr) DUMPRCallBack,
(**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
ResetShellPWD( ShellWh );
}
/*******************************************************************/
Boolean DoDUMPR( int16 ProcToken, WHandle ShellWh, int16 ProcID,
char *string )
{
int16 i, argc;
char *cp, argument[ 256 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
/* get arguments */
argc = (**MyShell).Proc[ ProcID ].argc;
dumprTypes = TRUE;
dumprIDs = TRUE;
dumprData = TRUE;
checkT = 0;
dumprIDStart = 0;
dumprIDEnd = 0;
dumprResType = 0L; /* no type specifier */
*dumpResName = '\0';
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
cp = argument;
if( *cp++ == '-' )
while( *cp )
switch( *cp++ )
{
case 'n' : /* Name */
i++;
GetArgv( ShellWh, ProcID, i, dumpResName );
break;
case 'i' : /* id's */
i++;
if( i < argc )
{
char *cp, nc, temp[ 64 ], num[ 64 ];
int32 lnum;
GetArgv( ShellWh, ProcID, i, temp );
cp = temp;
while( *cp && (*cp != ',') )
cp++;
nc = *cp;
if( *cp )
*cp = '\0';
CtoPstr( temp );
StringToNum( temp, &lnum );
dumprIDStart = (int16) lnum;
checkT++;
if( nc )
{
cp++;
CtoPstr( cp );
StringToNum( cp, &lnum );
dumprIDEnd = (int16) lnum;
checkT++;
}
}
break;
case 't' : /* Type */
i++;
if( i < argc )
{
char temp[ 256 ];
GetArgv( ShellWh, ProcID, i, temp );
dumprResType = StrToType( temp );
}
break;
}
}
for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
if( *argument != '-' )
DUMPRFile( ShellWh, ProcID, argument );
else
switch( argument[ 1 ] )
{
case 'n' :
case 'i' :
case 't' :
i++;
break;
}
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}